package com.ruoyi.web.xxj.contoller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.xxj.domain.ClassType;
import com.ruoyi.web.xxj.service.IClassTypeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程类型Controller
 *
 * @author ruoyi
 * @date 2024-02-29
 */
@Api(tags = "课程类型管理")
@RestController
@RequestMapping("/xxj/classType")
public class ClassTypeController extends BaseController {
    @Autowired
    private IClassTypeService classTypeService;

    /**
     * 查询课程类型列表
     */
    @ApiOperation("查询课程类型")
    @GetMapping("/list")
    public TableDataInfo list(ClassType classType) {
        startPage();
        List<ClassType> list = classTypeService.selectClassTypeList(classType);
        return getDataTable(list);
    }

    /**
     * 导出课程类型列表
     */
    @ApiOperation("导出课程类型")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassType classType) {
        List<ClassType> list = classTypeService.selectClassTypeList(classType);
        ExcelUtil<ClassType> util = new ExcelUtil<ClassType>(ClassType.class);
        util.exportExcel(response, list, "课程类型数据");
    }

    /**
     * 获取课程类型详细信息
     */
    @ApiOperation("获取课程类型详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(classTypeService.selectClassTypeById(id));
    }

    /**
     * 新增课程类型
     */
    @ApiOperation("新增课程类型")
    @PostMapping
    public AjaxResult add(@RequestBody ClassType classType) {
        return toAjax(classTypeService.insertClassType(classType));
    }

    /**
     * 修改课程类型
     */
    @ApiOperation("修改课程类型")
    @PutMapping
    public AjaxResult edit(@RequestBody ClassType classType) {
        return toAjax(classTypeService.updateClassType(classType));
    }

    /**
     * 删除课程类型
     */
    @ApiOperation("删除课程类型")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(classTypeService.deleteClassTypeByIds(ids));
    }

    /**
     * 查询课程类型列表
     */
    @ApiOperation("[小程序]查询课程类型列表")
    @GetMapping("/miniList")
    public AjaxResult miniList(ClassType classType) {
        List<ClassType> list = classTypeService.selectClassTypeList(classType);
        return AjaxResult.success(list);
    }
}
